﻿using PBO.Game.Img;
using PBO.Util;
using PokemonBattle.BattleRoom.Client;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace PBO.Forms.NetworkForm
{
    public partial class LogonRoomForm : Form
    {
        private List<Image> UserImages;

        public LogonRoomForm()
        {
            InitializeComponent();
            this.Icon = Properties.Resources.PokemonBall;
            UserImages = ImageHelper.GetAvatarList();
            MyImage.Image = UserImages[ImageIndex];
        }

        #region Button

        private void LogonButton_Click(object sender, EventArgs e)
        {
            string name = NameText.Text.Trim();
            if (!Regex.IsMatch(name, "^.+$", RegexOptions.Compiled)) return;
            Properties.Settings.Default.AutoLoginUser = AutoLogonCheck.Checked;
            Properties.Settings.Default.UserName = name;
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        #endregion

        private void ImageUpnButton_Click(object sender, System.EventArgs e)
        {
            if (ImageIndex < UserImages.Count - 1)
            {
                ImageIndex += 1;
                MyImage.Image = UserImages[ImageIndex];
            }
        }

        private void ImageDownButton_Click(object sender, System.EventArgs e)
        {
            if (ImageIndex > 0)
            {
                ImageIndex -= 1;
                MyImage.Image = UserImages[ImageIndex];
            }
        }

        public int ImageIndex
        {
            get { return Properties.Settings.Default.ImageIndex; }
            set { Properties.Settings.Default.ImageIndex = Convert.ToByte(value); }
        }

        public bool Advanced
        {
            get { return AdvanceLinkButton.Checked; }
        }

        public User UserInfo
        {
            get
            {
                User info = new User();
                info.ImageKey = Convert.ToByte(ImageIndex);
                info.Name = NameText.Text;
                return info;
            }
        }

    }
}
